<template>
	<view>
		<view class="topsMy  bgw p30">
			<view class="top_user ">
				<image class="userImg" :src="data.avatarImg" mode=""></image>
				<!-- <image class="userImg" src="../../static/icon/default_avatar.png" mode=""></image> -->
				<view class="userTxt">
					<p class="p1 one">
						{{data.name}}
					</p>
					<p class="p2 one">
						{{data.mobile}}
					</p>
				</view>
				<view @tap="openServe()" v-if="id !=0" class="userServe">
					<image src="../../static/image/icon_lianxi@2x.png" mode=""></image>
				</view>
				<view @tap="follow()" v-if="id !=0 && data.isFollow == false" class="userLabel">
					<image class="addIcons " src="../../static/image/addwhite.png" mode=""></image>
					关注
				</view>
				<view @tap="cancel()" v-if="id !=0 && data.isFollow == true" class="userLabels">
					已关注
				</view>
			</view>
			<view class="navs">
				<view>
					{{data.followQuantity}}
					<span>关注</span>
				</view>
				<view>
					{{data.fansQuantity}}
					<span>粉丝</span>
				</view>
				<view>
					{{data.praiseQuantity}}
					<span>获赞</span>
				</view>
			</view>
			<u-tabs-swiper v-if="id == 0" ref="uTabs" font-size="32"  :bold="bold"  active-color="#1BBF80" :list="list" :current="current"
			 @change="tabsChange" :is-scroll="false" swiperWidth="750"></u-tabs-swiper>
			<u-tabs-swiper v-if="id != 0" ref="uTabs" font-size="32"  :bold="bold" active-color="#1BBF80" :list="list2" :current="current"
			 @change="tabsChange" :is-scroll="false" swiperWidth="750"></u-tabs-swiper>
		</view>
		<view v-show="id == 0 " class="contents">
			<swiper :style="{'height':h}" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
				<swiper-item style="padding-top: 8rpx;">
					<scroll-view :style="{'height':h}" scroll-y @scrolltolower="goodsDatasB">
						<goodsData ref="goodsDatas" :url="goodsUrl" goodsType="3"></goodsData>
					</scroll-view>
				</swiper-item>
				<swiper-item>
					<scroll-view :style="{'height':h}" scroll-y @scrolltolower="dynamicsB">
						<dynamic urlType='isFollowFalse' ref="dynamics" :url="dynamicUrl"></dynamic>
					</scroll-view>
				</swiper-item>
				<swiper-item>
					<scroll-view :style="{'height':h}" scroll-y @scrolltolower="MyDynamicsB">
						<dynamicLike ref="MyDynamics" :url="likeDynamicUrl"></dynamicLike>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
		<view v-show="id != 0 " class="contents">
			<swiper :style="{'height':h}" :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish">
				<swiper-item>
					<scroll-view :style="{'height':h}" scroll-y @scrolltolower="AgoodsDatasB">
						<goodsData ref="AgoodsDatas" :url="goodsUrl" :id="id"></goodsData>
					</scroll-view>
				</swiper-item>
				<swiper-item>
					<scroll-view :style="{'height':h}" scroll-y @scrolltolower="AdynamicsB">
						<dynamic ref="Adynamics" :url="dynamicUrl" :id="id"></dynamic>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	import {
		othersDynamicUrl,
		DynamicMyUrl,
		myProductsUrl,
		productListUrl,
		userInfo,
		storeInfo,
		followAdd,
		dynamicFavoriteUrl,
		followCancel
	} from '@/api/api.js'
	import dynamicLike from '@/components/dynamic/dynamicLike.vue'
	export default {
		components: {
			dynamicLike
		},
		data() {
			return {
				id: 0,
				dynamicUrl: '',
				goodsUrl: '',
				likeDynamicUrl: '',
				list: [{
					name: '商品'
				}, {
					name: '动态'
				}, {
					name: '喜欢'
				}],
				list2: [{
					name: '商品'
				}, {
					name: '动态'
				}],
				data: [],
				activeColor: this.$u.color['Success'],
				bold: true, // 因为内部的滑动机制限制，请将tabs组件和swiper组件的current用不同变量赋值
				current: 0, // tabs组件的current值，表示当前活动的tab选项
				swiperCurrent: 0, // swiper组件的current值，表示当前那个swiper-item是活动的
				h: 0,

			};
		},
		onLoad(e) {
			if (e.id) {
				this.id = e.id
				this.dynamicUrl = othersDynamicUrl
				this.goodsUrl = productListUrl
			} else {
				this.likeDynamicUrl = dynamicFavoriteUrl
				this.dynamicUrl = DynamicMyUrl
				this.goodsUrl = myProductsUrl

			}
			uni.getSystemInfo({
				success: (res) => {
					console.log(res.windowHeight);
					let h = res.windowHeight
					this.h = h + "px"
					console.log(res.screenHeight);
				}
			});
			this.init()
			
			
			if (this.id != 0) { 
				setTimeout(()=>{
					this.$refs['AgoodsDatas'].inits();
					this.$refs['Adynamics'].inits(); 
				},400)
			
			}
		},
		onShow() {
			setTimeout(()=>{
				if (this.id == 0) {
					this.$refs['MyDynamics'].inits();
					this.$refs['dynamics'].inits();
					this.$refs['goodsDatas'].inits();
				} 
			},400) 
		}, 
		onPullDownRefresh() {
			if (this.id != 0) {
				this.$refs['AgoodsDatas'].inits();
				this.$refs['Adynamics'].inits(); 
			} else {
				this.$refs['MyDynamics'].inits();
				this.$refs['dynamics'].inits();
				this.$refs['goodsDatas'].inits();
			}
			uni.stopPullDownRefresh()
		},
		methods: {
			goodsDatasB(){
				this.$refs['goodsDatas'].checking();
			},
			dynamicsB(){
				this.$refs['dynamics'].checking();
			},
			MyDynamicsB(){
				this.$refs['MyDynamics'].checking();
			},
			AdynamicsB(){
				this.$refs['Adynamics'].checking();
			},
			AgoodsDatasB(){
				this.$refs['AgoodsDatas'].checking();
			},
			openServe() {
				let token = uni.getStorageSync('token')
				if (token == '') {
					uni.showToast({
						title: '未登录',
						icon: 'none'
					})
					return
				}
				// let mpId = plus.runtime.appid
				// let url = 'eper://weichat.xar.com/tochat?mobile=' + this.data.mobile + '&mpId=' + mpId
				// plus.runtime.openURL(url, res => {});
				 
				let goUrl = `${urls}/#/pages/login/login?mobile=${this.data.mobile}&serviceType=集市&token=${token}` 
				 uni.setStorageSync('openWebViewUrl',goUrl)
				let url = `../webView/webView?type=serve`  
				uni.navigateTo({
					url:url
				})
				
			},
			async cancel() {
				let data = await followCancel({
					id: this.data.id
				})
				if (data.code == 0) {
					this.data.isFollow = false
				}
			},
			async follow() {
				let data = await followAdd({
					id: this.data.id
				})
				if (data.code == 0) {
					this.data.isFollow = true
				}
			},
			async init() {
				let data;
				if (this.id != 0) {
					data = await storeInfo({
						id: this.id
					})
				} else {
					data = await userInfo()
				}
				this.data = data.data
			},
			goodsOB() {
				this.$refs['goods'].checking()
			},
			// tabs通知swiper切换
			tabsChange(index) {
				this.swiperCurrent = index;
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				let dx = e.detail.dx;
				this.$refs.uTabs.setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.uTabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			},
			// scroll-view到底部加载更多
			onreachBottom() {

			}
		}

	}
</script>

<style lang="less" scoped>
	@import './index.less';
</style>
